import 'package:farmer_app/common/card/bottom_card_component.dart';
import 'package:farmer_app/common/card/record_card_component.dart';
import 'package:flutter/material.dart';

import '../../../common/app_theme.dart';
import '../../../common/title/title_view.dart';


class WorkRecordComponent extends StatefulWidget {
  final int workSpaceId;
  final ScrollController scrollController;
  final AnimationController? animationController;

  const WorkRecordComponent({Key? key, required this.workSpaceId, required  this.scrollController, this.animationController}) : super(key: key);

  @override
  State<WorkRecordComponent> createState() => _WorkRecordComponentState();
}

class _WorkRecordComponentState extends State<WorkRecordComponent> {

  List<Widget> listViews = <Widget>[];


  @override
  Widget build(BuildContext context) {
    return FutureBuilder<bool>(
      future: getData(),
      builder: (BuildContext context, AsyncSnapshot<bool> snapshot) {
        if (!snapshot.hasData) {
          return const SizedBox();
        } else {
          return Container(
            color: AppTheme.background,
            child: ListView.builder(
              controller: widget.scrollController,
              padding: EdgeInsets.only(
                top: 24,
                bottom: MediaQuery.of(context).padding.bottom,
              ),
              itemCount: listViews.length,
              scrollDirection: Axis.vertical,
              itemBuilder: (BuildContext context, int index) {
                widget.animationController?.forward();
                return listViews[index];
              },
            ),
          );
        }
      },
    );
  }

  @override
  void initState() {
    initData();
    super.initState();
  }

  // 模拟数据通信
  Future<bool> getData() async {
    await Future<dynamic>.delayed(const Duration(milliseconds: 50));
    return true;
  }

  // test 初始化所有数据
  void initData() {
    const int count = 5;

    // listViews.add(
    //   WorkCardTabComponent(
    //     animation: Tween<double>(begin: 0.0, end: 1.0).animate(CurvedAnimation(
    //         parent: widget.animationController!,
    //         curve:
    //         Interval((1 / count) * 3, 1.0, curve: Curves.fastOutSlowIn))),
    //     animationController: widget.animationController!,
    //   ),
    // );

    listViews.add(
      RecordCardComponent(
        animation: Tween<double>(begin: 0.0, end: 1.0).animate(CurvedAnimation(
            parent: widget.animationController!,
            curve:
            Interval((1 / count) * 0, 1.0, curve: Curves.fastOutSlowIn))),
        animationController: widget.animationController!,
      ),
    );
    listViews.add(
      RecordCardComponent(
        animation: Tween<double>(begin: 0.0, end: 1.0).animate(CurvedAnimation(
            parent: widget.animationController!,
            curve:
            Interval((1 / count) * 0, 1.0, curve: Curves.fastOutSlowIn))),
        animationController: widget.animationController!,
      ),
    );
    listViews.add(
      RecordCardComponent(
        animation: Tween<double>(begin: 0.0, end: 1.0).animate(CurvedAnimation(
            parent: widget.animationController!,
            curve:
            Interval((1 / count) * 0, 1.0, curve: Curves.fastOutSlowIn))),
        animationController: widget.animationController!,
      ),
    );
    // listViews.add(
    //   BottomCardComponent(
    //       animation: Tween<double>(begin: 0.0, end: 1.0).animate(
    //           CurvedAnimation(
    //               parent: widget.animationController!,
    //               curve: Interval((1 / count) * 4, 1.0,
    //                   curve: Curves.fastOutSlowIn))),
    //       animationController: widget.animationController!),
    // );
  }
}
